package com.javaweb.service.impl;

import com.javaweb.aop.GranularType;
import com.javaweb.aop.TimeMeasure;
import com.javaweb.dao.UserDao;
import com.javaweb.model.User;
import com.javaweb.service.UserService;
import com.javaweb.service.dto.UserConditionDto;
import com.javaweb.service.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/9/23 12:36
 */
@TimeMeasure(granular = GranularType.MIL_SECOND)
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao ;
    @Override
    public User login(String username, String password) {
        User user = new User() ;
        if( user.getName().equals( "123")) {

        }
        return userDao.selectOne(username, password) ;
    }

    @Override
    public List<User> findUserByName(String username) {
        User user = new User() ;
        if( user.getName().equals( "123")) {

        }
        return userDao.selectByName(username) ;
    }

    @Override
    public List<UserDto> list(UserConditionDto userConditionDto) {
        return userDao.selectList(userConditionDto);
    }

    @Override
    public Integer add(UserDto userDto) {
        User user = new User();
        user.setName(userDto.getUsername());
        user.setPassword(userDto.getPassword());
        user.setGender(userDto.getGender());
        user.setSalt("123456");
        user.setCreateTime(new Date());
        return userDao.insert(user);
    }

    @Override
    public Integer changePassword(Integer userId, String newPassword) {
        return userDao.updatePassword(userId,newPassword);
    }
}
